<template>
	<view style="padding-bottom: 60rpx; box-sizing: border-box;">
		<view class="header">
			<view class="header-top">
				<span v-if="mustAnwser">*</span>
				<text>标题</text>
			</view>
			<textarea placeholder="请输入标题" placeholder-class="place" v-model="editForm.ti"></textarea>
		</view>
		<view class="xuanxiang">
			<view class="xxtitle">选项</view>
			<view class="xxmain">
				<view class="xxmain-item flex" v-for="(item,index) in editForm.da" :key="index">
					<view class="xxmain-item-left flex">
						<image :src="globalImg+'jianshao.png'" @tap="delInput(index)"></image>
						<input placeholder="输入选项" placeholder-class="placeholder" v-model="item.wen" />
					</view>
					<view class="xxmain-item-right flex">
						<image v-if="item.img" :src="item.img" @tap="choicePic(index)"></image>
						<image v-else :src="globalImg + 'pic.png'" @tap="choicePic(index)"></image>
						<radio color="#209FFC" style="transform: scale(0.7);" :checked="item.xuan == 2 ? 'chencked' : ''" @tap="oneRadio($event,index)"></radio>
					</view>
				</view>
				<view class="add-item flex">
					<view class="xxmain-item-left flex" @tap="addInput">
						<image :src="globalImg+'tianjia.png'"></image>
						<text>添加选项</text>
					</view>
					<view class="xxmain-item-right" @tap="batchAdd">批量添加</view>
				</view>
			</view>
		</view>
		<view class="set">
			<view class="set-title">设置</view>
			<view class="set-item flex">
				<text>切换至{{changeText}}</text>
				<switch @change="switch1Change" :checked='showXX' color="#209FFC" />
			</view>
			<view v-if="showXX">
				<view class="set-item flex">
					<text>最少选择</text>
					<view class="set-item-right flex">
						<picker @change="Least" :value="leastIndex" :range="numArray">
							<view class="picker">
								{{editForm.zuishao ? editForm.zuishao : ''}}
							</view>
						</picker>
						<image :src="imgurl+'youjiantou.png'"></image>
					</view>
				</view>
				<view class="set-item flex">
					<text>最多选择</text>
					<view class="set-item-right flex">
						<picker @change="Most" :value="mostIndex" :range="numArray">
							<view class="picker">
								{{editForm.zuiduo ? editForm.zuiduo : ''}}
							</view>
						</picker>
						<image :src="imgurl+'youjiantou.png'"></image>
					</view>
				</view>
			</view>
			<view class="set-item flex">
				<text>此题目必须回答</text>
				<switch @change="switch2Change" color="#209FFC" :checked='mustAnwser' />
			</view>
			<view class="set-item flex">
				<text>一行显示项数</text>
				<view class="set-item-right flex">
					<picker @change="bindPickerChange" :value="lineindex" :range="lineArray">
						<view class="picker">
							{{lineArray[lineindex]}}
						</view>
					</picker>
					<image :src="imgurl+'youjiantou.png'"></image>
				</view>
			</view>
			<view class="set-item-other flex" @tap="showSet ? showSet = false : showSet = true" v-if="showSet">
				<text>逻辑设置</text>
				<image :src="imgurl+'xiajiantou.png'"></image>
			</view>
			<view class="showset" v-else>
				<view class="set-item flex" @tap="showCondition">
					<text>显示条件</text>
					<view class="set-item-right flex">
						<text v-text="editForm.xiantiao ? '已设置' : '未设置'">未设置</text>
						<image :src="imgurl+'youjiantou.png'"></image>
					</view>
				</view>
				<view class="set-item flex" @tap="jumpQuestion">
					<text>跳题设置</text>
					<view class="set-item-right flex">
						<text v-text="editForm.xuantiao =='' ? '未设置' : '已设置'">未设置</text>
						<image :src="imgurl+'youjiantou.png'"></image>
					</view>
				</view>
			</view>
		</view>
		<button class="buttoncss" @tap="save">确认</button>
	</view>
</template>

<script>
	import api from "@/common/api.js";
	import {
		baseURL
	} from "@/common/http.js";
	import app from "../../../App.vue"
	export default {
		data() {
			return {
				title_number: '', //当前题目序号
				editForm: {
					ti: '',
					da: [{
						xuan: 1,
						img: app.globalData.imgurls + 'pic.png',
						wen: ''
					}, {
						xuan: 1,
						img: app.globalData.imgurls + 'pic.png',
						wen: ''
					}],
					zuishao: '',
					zuiduo: '',
					xuan: '',
					pid: '',
					beizhu: '',
					beitiao: '',
					order: '',
					xiantiao: '',
					xuantiao: '',
					yan: ''
				},
				globalImg: app.globalData.imgurls,
				lineArray: ['1', '2'], //显示项数
				lineindex: 0,
				showXX: true, // 显示选择
				mustAnwser: true, // 是否必答
				changeText: '',
				numArray: ['不限'], //最多选择
				leastIndex: 0,
				mostIndex: 0,
				showSet: true, //显示设置
				index: '', // 题目下标
				len: '', // 问卷题目数
				subKey: true // 是否保存修改
				/* da: [],
				imgpic: "",
				imgurl: "",
				title: '',
				array: [{
					xuan: 1,
					img: app.globalData.imgurls + 'pic.png',
					wen: ''
				}, {
					xuan: 1,
					img: app.globalData.imgurls + 'pic.png',
					wen: ''
				}], //默认显示一
				inputVal: [], //所有input的内容
				showXX: true, //显示选择
				lineArray: ['1', '2'], //显示项数
				lineindex: 0,
				leastArray: ['不限'], //最少选择
				leastindex: 0,
				mostArray: ['不限'], //最多选择
				mostindex: 0,
				zuiduo: '',
				zuishao: '',
				mustValue: 2, //是否必答
				pid: 2, //是否多选
				wenid: '',
				xuanid: '',
				id: '',
				item: '', //显示条件
				items: '', //跳题设置
				xuanid: '',
				xiantiao: '',
				index: '',
				len: '' */
			};
		},
		methods: {
			/* getTitle(e) {
				this.title = e.detail.value
			},
			//添加选项
			addInput() {
				this.array.push({
					xuan: 1,
					img: app.globalData.imgurls + 'pic.png',
					wen: ""
				})
			},
			//删除选项
			delInput(e) {
				var nowidx = e; //当前索引
				var oldInputVal = this.inputVal; //所有的input值
				var oldarr = this.array; //循环内容
				oldarr.splice(nowidx, 1); //删除当前索引的内容，这样就能删除view了
				oldInputVal.splice(nowidx, 1); //view删除了对应的input值也要删掉
				if (oldarr.length < 0) {
					oldarr = [0]
				}
				this.array = oldarr
				this.inputVal = oldInputVal
				this.leastArray = ['不限'] //最少选项
				this.mostArray = ['不限'] //最多选项
				this.inputVal.forEach((item, index) => {
					this.leastArray.push(index + 1)
					this.mostArray.push(index + 1)
				})
			},
			//获取input的值
			getInputVal(e) {
				var nowIdx = e.currentTarget.dataset.index; //获取当前索引
				var val = e.detail.value; //获取输入的值
				var oldVal = this.inputVal;
				oldVal[nowIdx] = val; //修改对应索引值的内容
			},
			//失去焦点
			getIndex(e) {
				this.leastArray = ['不限'] //最少选项
				this.mostArray = ['不限'] //最多选项
				this.inputVal.forEach((item, index) => {
					this.leastArray.push(index + 1)
					this.mostArray.push(index + 1)
				})
			},
			//此项是否是正确答案
			oneRadio(e, index) {
				var ids = index
				let that = this
				if (this.showXX == false) {
					this.array.forEach((item, index) => {
						ids === index ? this.array[index].xuan = 2 : this.array[index].xuan = 1
					})
				} else {
					this.array[index].xuan == 1 ? this.array[index].xuan = 2 : this.array[index].xuan = 1
				}
			},
			//上传图片
			choicePic(index) {
				let ids = index
				let that = this
				this.array.forEach((item, index) => {
					if (ids === index) {
						uni.chooseImage({
							count: 1,
							sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
							sourceType: ['album'], //从相册选择
							success: function(res) {
								uni.getFileSystemManager().readFile({
									filePath: res.tempFilePaths[0], //选择图片返回的相对路径
									encoding: 'base64', //编码格式
									success: res => { //成功的回调
										that.array[index].img = 'data:image/jpeg;base64,' + res.data //不加上这串字符，在页面无法显示的哦
									}
								});
							}
						});
					}
				})
			},
			//批量添加
			batchAdd() {
				uni.navigateTo({
					url: "../batchAdd/batchAdd?type=" + '2'
				})
			},
			//切换至单选题
			switch1Change(e) {
				if (e.target.value == true) {
					this.pid = 1
					this.showXX = true
					uni.setNavigationBarTitle({
						title: '多选题'
					})
				} else {
					this.showXX = false
					this.pid = 2
					uni.setNavigationBarTitle({
						title: '单选题'
					})
				}
			},
			//此题目是否必答
			switch2Change(e) {
				if (e.target.value == true) {
					this.mustValue = 2
				} else {
					this.mustValue = 1
				}
			},
			//逻辑设置显示
			showSet() {
				this.shoeset = false
			},
			//最少显示
			Least(e) {
				let that = this
				this.leastindex = e.target.value
				that.zuishao = this.leastArray[this.leastindex]
				if (this.mostArray[this.mostindex] != "不限") {
					if (this.leastArray[this.leastindex] > this.mostArray[this.mostindex]) {
						uni.showModal({
							title: '',
							showCancel: false,
							confirmText: "知道了",
							confirmColor: 'skyblue',
							content: '最多项不能小于最小项',
							success: function(res) {
								if (res.confirm) {
									that.leastindex = 0
								}
							}
						});
					}
				}
			},
			//最多显示
			Most(e) {
				let that = this
				this.mostindex = e.target.value
				that.zuiduo = this.mostArray[this.mostindex]
				if (this.leastArray[this.leastindex] != "不限") {
					if (this.leastArray[this.leastindex] > this.mostArray[this.mostindex]) {
						uni.showModal({
							title: '',
							showCancel: false,
							confirmText: "知道了",
							confirmColor: 'skyblue',
							content: '最多项不能小于最小项',
							success: function(res) {
								if (res.confirm) {
									that.mostindex = 0
								}
							}
						});
					}
				}
			},
			//显示项数
			bindPickerChange(e) {
				this.lineindex = e.target.value
			},
			//显示条件
			showCondition() {
				if (this.index == 0) {
					uni.showToast({
						title: "第一题不能设置显示条件",
						icon: 'none',
						duration: 2000
					})
				} else {
					uni.navigateTo({
						url: "../condition/condition?id=" + this.id + '&wenid=' + this.wenid + '&type=' + 2 + '&xuanid=' + this.xuanid + '&key=' + 2
					})
				}
			},
			//跳题设置
			jumpQuestion() {
				if (this.index == this.len - 1) {
					uni.showToast({
						title: "最后一题不能跳题",
						icon: 'none',
						duration: 2000
					})
				} else {
					uni.navigateTo({
						url: "../jumpQuestion/jumpQuestion?type=" + 2 + '&id=' + this.id + '&wenid=' + this.wenid + '&xiantiao=' + JSON.stringify(this.xiantiao)
					})
				}
			},
			save() {
				let that = this
				let arr = JSON.parse(JSON.stringify(this.array));
				arr.forEach(item => {
					if (item.img == "../../../static/images/pic.png") {
						item.img = ""
					}
					if (item.xuan == 2) {
						item.xuan = 2
					} else {
						item.xuan = 1
					}
				})
				if (this.pid == 1) {
					var data = {
						id: this.id,
						api: 'wenupdate',
						ti: this.title,
						xuan: this.mustValue,
						wenid: this.wenid,
						data: arr,
						xuantiao: this.xuanid ? this.xuanid : '',
						xiantiao: this.xiantiao ? JSON.stringify(this.xiantiao) : '',
						yan: this.lineArray[this.lineindex],
						order: '',
						pid: this.pid
					}
				} else {
					var data = {
						api: 'wenupdate',
						id: this.id,
						ti: this.title,
						xuan: this.mustValue,
						wenid: this.wenid,
						data: arr,
						xuantiao: this.xuanid ? this.xuanid : '',
						yan: this.lineArray[this.lineindex],
						order: '',
						pid: this.pid,
						xiantiao: this.xiantiao ? JSON.stringify(this.xiantiao) : '',
						zuishao: this.leastArray[this.leastindex],
						zuiduo: this.mostArray[this.mostindex]
					}
				}
				if (this.inputVal.length < 2) {
					uni.showToast({
						title: "最少两个选项",
						icon: 'none'
					})
				} else if (this.title == "") {
					uni.showToast({
						title: "题目不能为空",
						icon: 'none'
					})
				} else {
					api.add(data).then(res => {
						if (res.code == 200) {
							if (app.globalData.flag == 1) {
								uni.navigateTo({
									url: '../../editDiaocha/editDiaocha?wenid=' + that.wenid
								})
							} else if (app.globalData.flag == 2) {
								uni.navigateTo({
									url: '../../createForm/editForm/editForm?wenid=' + that.wenid
								})
							} else {
								uni.navigateTo({
									url: '../../createVote/editVote/editVote?wenid=' + that.wenid
								})
							}
						}
					}).catch(err => {
						console.log(err)
					})
				}
			},
			look() {
				let that = this
				let data = {
					api: 'wenudan',
					id: this.id
				}
				api.look(data).then(res => {
					if (res.code == 200) {
						if (res.date.xuantiao != null) {
							that.xuanid = res.date.xuantiao
						}
						if (res.date.xiantiao != null) {
							that.xiantiao = JSON.parse(res.date.xiantiao)
						}
						if (res.date.zuiduo != null) {
							that.zuiduo = res.date.zuiduo
						} else {
							that.zuiduo = '不限'
						}
						if (res.date.zuishao != null) {
							that.zuishao = res.date.zuishao
						} else {
							that.zuishao = '不限'
						}
						if (res.date.xuan == 2) {
							this.mustValue = 2
						} else {
							this.mustValue = 1
						}
						res.date.da.map((item) => {
							if (item.xuan == 2) {
								item.xuan = 2
							} else {
								item.xuan = 1
							}
							if (item.img == "" || item.img == null) {
								item.img = "../../../static/images/pic.png"
							}
							this.inputVal.push(item.wen)
							return item
						})
						this.inputVal.forEach((item, index) => {
							this.leastArray.push(index + 1)
							this.mostArray.push(index + 1)
						})
						this.title = res.date.ti
						this.array = res.date.da.concat(this.da)
						this.pid = res.date.pid
					}
				}).catch(err => {
					console.log(err)
				})
			},
			lookset() {
				let that = this
				let data = {
					api: 'wenudan',
					id: this.id
				}
				api.look(data).then(res => {
					if (res.code == 200) {
						if (res.date.xuantiao != null) {
							that.xuanid = res.date.xuantiao
						}
						if (res.date.xiantiao != null) {
							that.xiantiao = JSON.parse(res.date.xiantiao)
						}
						if (res.date.zuiduo != null) {
							that.zuiduo = res.date.zuiduo
						} else {
							that.zuiduo = '不限'
						}
						if (res.date.zuishao != null) {
							that.zuishao = res.date.zuishao
						} else {
							that.zuishao = '不限'
						}
						if (res.date.xuan == 1) {
							this.mustValue = 1
						} else {
							this.mustValue = 2
						}
						res.date.da.map((item) => {
							if (item.xuan == 2) {
								item.xuan = 2
							} else {
								item.xuan = 1
							}
							if (item.img == "" || item.img == null) {
								item.img = "../../../static/images/pic.png"
							}
							this.inputVal.push(item.wen)
							return item
						})
						this.inputVal.forEach((item, index) => {
							this.leastArray.push(index + 1)
							this.mostArray.push(index + 1)
						})
						this.title = res.date.ti
						this.array = res.date.da.concat(this.da)
						this.pid = res.date.pid
					}
				}).catch(err => {
					console.log(err)
				})
			} */
			//此项是否是正确答案
			oneRadio(e, index) {
				let idx = index
				if (this.showXX == false) {
					this.editForm.da.forEach((item, index) => {
						idx === index ? this.editForm.da[index].xuan = 2 : this.editForm.da[index].xuan = 1
					})
				} else {
					this.editForm.da[index].xuan == 1 ? this.editForm.da[index].xuan = 2 : this.editForm.da[index].xuan = 1
				}
			},
			//上传图片
			choicePic(index) {
				let idx = index
				this.editForm.da.forEach((item, index) => {
					if (idx === index) {
						uni.chooseImage({
							count: 1,
							sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
							sourceType: ['album'], //从相册选择
							success: (res) => {
								uni.getFileSystemManager().readFile({
									filePath: res.tempFilePaths[0], //选择图片返回的相对路径
									encoding: 'base64', //编码格式
									success: res => { //成功的回调
										this.editForm.da[index].img = 'data:image/jpeg;base64,' + res.data //不加上这串字符，在页面无法显示的哦
									}
								})
							}
						})
					}
				})
			},
			//批量添加
			batchAdd() {
				this.$store.commit('setTiEditForm', this.editForm)
				uni.navigateTo({
					url: "../batchAdd/batchAdd?type=" + 2
				})
			},
			//显示条件
			showCondition() {
				console.log(this.editForm, 'EDIT')
				if (this.index == 0) {
					uni.showToast({
						title: "第一题不能设置显示条件",
						icon: 'none',
						duration: 2000
					})
				} else {
					console.log(this.editForm, 'EDIT')
					this.$store.commit('setTiEditForm', this.editForm)
					uni.navigateTo({
						url: "../condition/condition?id=" + this.id + '&wenid=' + this.editForm.wenid + '&type=' + this.editForm.pid +
							'&xiantiao=' + this.editForm.xiantiao
					})
				}
			},
			//跳题设置
			jumpQuestion() {
				this.$store.commit('setTiEditForm', this.editForm)
				if (this.index == this.len - 1) {
					uni.showToast({
						title: "最后一题不能跳题",
						icon: 'none',
						duration: 2000
					})
				} else {
					uni.navigateTo({
						url: "../jumpQuestion/jumpQuestion?type=" + 2 + '&id=' + this.id + '&wenid=' + this.editForm.wenid +
							'&xuantiao=' + this.editForm.xuantiao + '&tit_num=' + (parseInt(this.title_number) + 1)
					})
				}
			},
			//添加选项
			addInput() {
				this.editForm.da.push({
					xuan: 1,
					img: this.globalImg + 'pic.png',
					wen: ""
				})
				this.numArray.push(this.numArray.length)
				this.leastIndex = 0
				this.mostIndex = 0
				this.editForm.zuiduo = this.numArray[0]
				this.editForm.zuishao = this.numArray[0]
			},
			//删除选项
			delInput(e) {
				console.log('sssss', e)
				let idx = e // 当前索引
				this.editForm.da.forEach((el, index) => {
					if (index == idx) {
						this.editForm.da.splice(index, 1)
						this.numArray.splice(this.numArray.length-1, 1)
					}
				})
				this.leastIndex = 0
				this.mostIndex = 0
				this.editForm.zuiduo = this.numArray[0]
				this.editForm.zuishao = this.numArray[0]
			},
			//最少显示
			Least(e) {
				let idx = e.target.value
				this.leastIndex = e.target.value
				if (this.editForm.zuiduo != '不限') {
					console.log(this.numArray[idx], idx, this.editForm.zuiduo, 'SD')
					if (idx != 0 && this.numArray[idx] > this.editForm.zuiduo) {
						uni.showModal({
							title: '',
							showCancel: false,
							confirmText: "知道了",
							confirmColor: 'skyblue',
							content: '最少项不能多于最多项',
							success: (res) => {
								if (res.confirm) {
									this.leastIndex = 0
								}
							}
						})
					} else {
						this.editForm.zuishao = this.numArray[idx]
					}
				} else {
					this.editForm.zuishao = this.numArray[idx]
				}
			},
			//最多显示
			Most(e) {
				let idx = e.target.value
				this.mostIndex = e.target.value
				if (this.editForm.zuishao != "不限") {
					if (idx != 0 && this.numArray[idx] < this.editForm.zuishao) {
						uni.showModal({
							title: '',
							showCancel: false,
							confirmText: "知道了",
							confirmColor: 'skyblue',
							content: '最多项不能小于最少项',
							success: (res) => {
								if (res.confirm) {
									this.mostIndex = 0
								}
							}
						})
					} else {
						this.editForm.zuiduo = this.numArray[idx]
					}
				} else {
					this.editForm.zuiduo = this.numArray[idx]
				}
			},
			//切换至单选题
			switch1Change(e) {
				if (e.target.value == true) {
					this.editForm.pid = 2
					this.showXX = true
					uni.setNavigationBarTitle({
						title: '多选题'
					})
					this.changeText = '单选'
				} else {
					this.showXX = false
					this.editForm.pid = 1
					uni.setNavigationBarTitle({
						title: '单选题'
					})
					this.changeText = '多选'
				}
			},
			//此题目是否必答
			switch2Change(e) {
				if (e.target.value == true) {
					this.editForm.xuan = 2
					this.mustAnwser = true
				} else {
					this.editForm.xuan = 1
					this.mustAnwser = false
				}
			},
			// 设置一行显示项数
			bindPickerChange(e) {
				this.lineindex = e.target.value
			},
			// 获取题目详情
			getInfo(id) {
				api.look({
					api: 'wenudan',
					id: this.id
				}).then(res => {
					if (res.code == 200) {
						this.editForm = res.date
						this.lineindex = this.editForm.yan - 1
						if (this.editForm.pid == 2) {
							this.showXX = true
							this.changeText = '单选'
							this.editForm.zuishao ? '' : this.editForm.zuishao = '不限'
							this.editForm.zuiduo ? '' : this.editForm.zuiduo = '不限'
						} else {
							this.showXX = false
							this.changeText = '多选'
						}
						if (this.editForm.xuan == 2) {
							this.mustAnwser = true
						} else {
							this.mustAnwser = false
						}
						this.editForm.da.length
						this.editForm.da.forEach((el, index) => {
							this.numArray.push(index + 1)
						})
						if (this.editForm.pid == 1) {
							uni.setNavigationBarTitle({
								title: '单选题'
							})
						} else if (this.editForm == 2) {
							uni.setNavigationBarTitle({
								title: '多选题'
							})
						}
						this.editForm.da.forEach((el, index) => {
							if (el.img && el.img != '') {

							} else {
								el.img = "../../../static/images/pic.png"
							}
						})
						this.$store.commit('setTiEditForm', this.editForm)
					}
				}).catch(err => {
					console.log(err)
				})
			},
			save() {
				this.editForm.api = 'wenupdate'
				console.log(this.editForm.da)
				for (let el in this.editForm.da) {
					if (this.editForm.da[el].wen && this.editForm.da[el].wen != '') {
						if (this.editForm.da[el].img && this.editForm.da[el].img == "../../../static/images/pic.png") {
							this.editForm.da[el].img = ""
						}
						this.subKey = true
						continue
					} else {
						uni.showToast({
							title: '选项内容不能为空',
							icon: 'none',
							duration: 1500
						})
						this.subKey = false
						break
					}
				}
				this.editForm.yan = parseInt(this.lineindex) + 1
				if (this.editForm.pid == 2) {
					if (this.editForm.zuishao && this.editForm.zuishao != '') {
						this.editForm.xuan = 2
					}
				} else {
					delete this.editForm.zuishao
					delete this.editForm.zuiduo
				}
				console.log('sssss',this.editForm.da)
				for(let i = 0; i < this.editForm.da.length; i++) {
					for(let j = 0; j < this.editForm.da.length; j++) {
						if(i != j && this.editForm.da[i]['wen'] == this.editForm.da[j]['wen']){
							uni.showToast({
								title: "选项内容不可相同哦~",
								icon: 'none'
							})
							return
						}
					}
				}
				if (this.editForm.da.length < 2) {
					uni.showToast({
						title: "最少两个选项",
						icon: 'none'
					})
				} else if (this.editForm.ti == "") {
					uni.showToast({
						title: "题目不能为空",
						icon: 'none'
					})
				} else {
					if(this.subKey) {
						api.add(this.editForm).then(res => {
							if (res.code == 200) {
								uni.showToast({
									title: '保存成功',
									icon: 'success',
									duration: 1500,
									success: () => {
										setTimeout(() => {
											if (app.globalData.flag == 1) {
												uni.redirectTo({
													url: '../../editDiaocha/editDiaocha?wenid=' + this.editForm.wenid
												})
											} else if (app.globalData.flag == 2) {
												uni.redirectTo({
													url: '../../createForm/editForm/editForm?wenid=' + this.editForm.wenid
												})
											} else {
												uni.redirectTo({
													url: '../../createVote/editVote/editVote?wenid=' + this.editForm.wenid
												})
											}
										}, 1500)
									}
								})
							}
						}).catch(err => {
							console.log(err)
						})
					}
				}
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad(options) {
			this.title_number = options.index
			if (this.$store.state.tiIndex) {
				this.index = this.$store.state.tiIndex
			}
			this.len = app.globalData.len
			if (options.id) {
				this.id = options.id
				this.getInfo(this.id)
			} else {
				this.editForm = this.$store.state.tiEditForm
				if (this.editForm.pid == 2) {
					this.showXX = true
					this.changeText = '单选'
				} else {
					this.showXX = false
					this.changeText = '多选'
				}
				if (this.editForm.xuan == 2) {
					this.mustAnwser = true
				} else {
					this.mustAnwser = false
				}
				this.editForm.da.length
				this.editForm.da.forEach((el, index) => {
					this.numArray.push(index + 1)
				})
				if (this.editForm.pid == 1) {
					uni.setNavigationBarTitle({
						title: '单选题'
					})
				} else if (this.editForm == 2) {
					uni.setNavigationBarTitle({
						title: '多选题'
					})
				}
				'xuantiao' in options ? this.editForm.xuantiao = options.xuantiao : ''
				if (this.editForm.xuantiao === 0) {
					this.editForm.xuantiao = ''
				}
				'xiantiao' in options ? this.editForm.xiantiao = options.xiantiao : ''
				if (options.da) {
					let arr = []
					let val = options.da.replace(/(\n)/g, ',')
					arr = val.split(",")
					arr.forEach((item, index) => {
						this.editForm.da.push({
							xuan: 1,
							img: app.globalData.imgurls + 'pic.png',
							wen: item
						})
					})
				}
			}
			/* let that = this
			if(options.id) {
				that.id = options.id
				that.$store.commit('setDuoId', options.id)
			} else {
				that.id = that.$store.state.duoId
			}
			if(options.wenid) {
				that.wenid = options.wenid
				that.$store.commit('setWenId', options.wenid)
			} else {
				that.wenid = that.$store.state.wenid
			}
			if(this.$store.state.tiIndex) {
				this.index = this.$store.state.tiIndex
			}
			this.len = app.globalData.len
			this.imgurl = app.globalData.imgurls
			if (options.xiantiao && options.xiantiao !== "undefined") {
				this.xiantiao = JSON.parse(options.xiantiao)
			}
			if (options.xuantiao && options.xuantiao !== "undefined") {
				that.lookset()
			} else {
				that.xuanid = options.xuanid
				that.look()
			}
			this.leastArray = ['不限'] //最少选
			this.mostArray = ['不限'] //最少选
			if (options.da) {
				let b = []
				let val = options.da.replace(/(\n)/g, ',')
				that.da = []
				b = val.split(",")
				b.forEach((item, index) => {
					that.da.push({
						xuan: 1,
						img: app.globalData.imgurls + 'pic.png',
						wen: item
					})
				})
				this.inputVal = this.inputVal.concat(b)
				this.inputVal.forEach((item, index) => {
					this.leastArray.push(index + 1)
					this.mostArray.push(index + 1)
				})
			} */
		}
	}
</script>

<style lang="scss">
	page {
		background: #F0F0F0;
		font-family: PingFang SC;
		font-weight: 500;
	}

	.header {
		width: 100%;
		background: #fff;
		padding: 20rpx 0rpx;

		.header-top {
			width: 690rpx;
			margin: 0 auto;
			color: #333;
			font-size: 32rpx;

			span {
				color: #ff0000;
				margin-right: 10rpx;
			}
		}

		textarea {
			padding: 20rpx 0 0 30rpx;
			width: 690rpx;
			margin: 10rpx auto;
			box-sizing: border-box;
			height: 100rpx;
			border: 1rpx solid #DFDFDF;
			border-radius: 10rpx;
		}
	}

	.place {
		color: #999;
		font-weight: normal;
		font-size: 30rpx;
	}

	.xuanxiang {
		background: #fff;

		.xxtitle {
			width: 100%;
			height: 50rpx;
			line-height: 50rpx;
			padding-left: 30rpx;
			background: #F0F0F0;
			color: #999;
			font-size: 24rpx;
		}

		.xxmain {
			width: 690rpx;
			margin: 0 auto;

			.xxmain-item {
				height: 100rpx;
				border-bottom: 1rpx solid #DFDFDF;
				justify-content: space-between;

				.xxmain-item-left {
					width: 90%;
					height: 100rpx;

					input {
						width: 90%;
						height: 100rpx;
					}
				}

				.xxmain-item-right {
					height: 100rpx;
					line-height: 100rpx;

					text {
						display: inline-block;
						line-height: 80rpx;
						height: 100rpx;
					}
				}
			}

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}

	.add-item {
		height: 100rpx;
		border-bottom: 1rpx solid #DFDFDF;
		justify-content: space-between;

		.xxmain-item-left {
			width: 70%;
			height: 100rpx;

			text {
				width: 90%;
				height: 100rpx;
				line-height: 100rpx;
				display: inline-block;
				color: #209FFC;
				font-size: 30rpx;
			}
		}

		.xxmain-item-right {
			color: #209FFC;
			border: 1rpx solid #209FFC;
			padding: 10rpx 20rpx;
			border-radius: 25rpx;
			font-size: 24rpx;
		}
	}

	.set {
		background: #fff;

		.set-title {
			width: 100%;
			height: 50rpx;
			line-height: 50rpx;
			padding-left: 30rpx;
			background: #F0F0F0;
			color: #999;
			font-size: 24rpx;
		}

		.set-item {
			width: 690rpx;
			height: 100rpx;
			line-height: 100rpx;
			margin: 0 auto;
			justify-content: space-between;
			border-bottom: 1rpx solid #DFDFDF;

			.set-item-right {

				text {
					width: 400rpx;
					height: 100rpx;
					text-align: right;
					display: inline-block;
				}

				image {
					width: 45rpx;
					height: 50rpx;
				}
			}

			text {
				color: #333;
				font-size: 30rpx;
			}
		}

		.set-item-other {
			width: 690rpx;
			height: 100rpx;
			line-height: 100rpx;
			margin: 0 auto;
			justify-content: center;

			image {
				width: 40rpx;
				height: 25rpx;
				margin-left: 10rpx;
			}

		}
	}

	.buttoncss {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		color: #fff;
		font-size: 40rpx;
		border-radius: 50rpx;
		background: #209FFC;
		margin-top: 50rpx;
	}

	.picker {
		width: 400rpx;
		height: 100rpx;
		line-height: 100rpx;
		text-align: right;
	}
</style>
